package com.ybg.config.security;
import java.io.Serializable;
import java.util.Collection;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.SpringSecurityCoreVersion;

public class MyAuthenticationToken extends AbstractAuthenticationToken implements Serializable {
	
	private static final long	serialVersionUID	= SpringSecurityCoreVersion.SERIAL_VERSION_UID;
	// ~ Instance fields
	// ================================================================================================
	private final Object		principal;
	// private Object credentials;
	
	// ~ Constructors
	// ===================================================================================================
	/** This constructor can be safely used by any code that wishes to create a <code>UsernamePasswordAuthenticationToken</code>, as the {@link #isAuthenticated()} will return <code>false</code>. */
	public MyAuthenticationToken(Object principal) {
		super(null);
		this.principal = principal;
		// this.credentials = credentials;
		setAuthenticated(true);
	}
	
	/** This constructor should only be used by <code>AuthenticationManager</code> or <code>AuthenticationProvider</code> implementations that are satisfied with producing a trusted (i.e. {@link #isAuthenticated()} = <code>true</code>) authentication token.
	 *
	 * @param principal
	 * @param credentials
	 * @param authorities */
	public MyAuthenticationToken(Object principal, Collection<? extends GrantedAuthority> authorities) {
		super(authorities);
		this.principal = principal;
		super.setAuthenticated(true); // must use super, as we override
	}
	
	// ~ Methods
	// ========================================================================================================
	public Object getPrincipal() {
		return this.principal;
	}
	
	public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
		super.setAuthenticated(true);
	}
	
	// @Override
	// public void eraseCredentials() {
	// super.eraseCredentials();
	// }
	@Override
	public Object getCredentials() {
		return null;
	}
}
